var homelibURL = "nieuwsDB.php" ;

// function that displays an error message
function displayError(message)
{
    // display error message, with more technical details if debugMode is true
    alert("Error accessing the server! " +
        (debugMode ? message : ""));
}

// function that displays a PHP error message
function displayPHPError(error)
{
    displayError ("Error number :" + error.errno + "\r\n" +
        "Text :"+ error.text + "\r\n" +
        "Location :" + error.location + "\r\n" +
        "Line :" + error.line + + "\r\n");
}

function retrieveAllNews()
{
    $.ajax({
        url: homelibURL,
        type: 'POST',
        data: $.param({
            mode: 'RetrieveAllNew'
        }),
        dataType: 'json',
        error: function(xhr, textStatus, errorThrown) {
            displayError(textStatus);
        },
        success: function(data, textStatus) {
            if(data.errno != null)
                displayPHPError(data);
            else
                readAllMessages(data);
            // restart sequence
            setTimeout("retrieveAllNews();", updateInterval);
        }
    });
}

function readAllMessages(data, textStatus)
{
    // display the messages retrieved from server
    $.each(data.messages, function(i, message) {
        // compose the HTML code that displays the message
        var htmlMessage = "";
       // htmlMessage += "<a name=\""+message.id_nieuws+"\"></a>";
        htmlMessage += "<input type=\"CHECKBOX\" name=\"formDoor[]\"  value=\""+message.id_nieuws+"\"> " +  message.titel + "<hr>";
        // display the message
        $('#delete')[0].innerHTML += htmlMessage;

    });
}


$(document).ready(function()
{
    retrieveAllNews();
});